<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .ad{
            position: fixed;
            right: 0;
            bottom: 0;
            width: 200px;
            height: 200px;
            background: red;
        }
        .ad > span {
            float: right;
            width: 30px;
            height: 30px;
            background-color: #ff0;
            text-align: center;
            line-height: 30px;
            /* 加个手 */
            cursor: pointer;
        }
    </style>
</head>
<body>

    <div class="ad" id="ad">
        <span>X</span>
        <p>
            <span id="show">10</span>
            s之后自动关闭
        </p>
    </div>

    <script>

        var oSpan = document.getElementById('show') ;
        var oAd = document.getElementById('ad') ;

        // 计时器每隔1s就减一

        var count = 10 ;

        var t = setInterval(function () {  
            count-- ;
            oSpan.innerHTML = count ;
            if(count === 0) {
                oAd.style.display = 'none' ;
                // 定时器需要结束
                clearInterval(t) ;
            }
        } , 1000)


        // 点击事件  X    记得清除定时器

        
    </script>
    
</body>
</html>